package cn.uexpo.lhz.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

import java.util.Random;

/**
 * @ClassName HuangXiangXiang
 * @Date 2020/9/19 0:10
 * @Version V1.0
 **/
public class sendEmailCode {

    @Autowired
    MailSender mailSender;


    public String send(String toEmail) {
        //生成随机验证码
         String checkCode = String.valueOf(new Random().nextInt(899999) + 100000);
         SimpleMailMessage message = new SimpleMailMessage();
         message.setFrom("15994054231@163.com");
         message.setTo("1477227147@qq.com");
         message.setSubject("这是一个邮件主题——系统邮件");
         message.setText("您正在修改您的密码，本次验证码为：" + checkCode + "\n 如非本人操作，请忽略！谢谢");
         mailSender.send(message);
         System.out.println("邮件发送成功");
         return checkCode;
    }


}
